package lanou.autohome.recommend.fragments;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import lanou.autohome.basetool.BaseFragment;
import lanou.autohome.basetool.NetTool;
import lanou.autohome.R;
import lanou.autohome.URLValues;
import lanou.autohome.recommend.adapters.BulletinAdapter;
import lanou.autohome.recommend.beans.BulletinBean;

/**
 * Created by dllo on 16/8/15.
 * 推荐 -> 快报
 */
public class BulletinFragment extends BaseFragment {


    private RecyclerView recyclerView;
    private BulletinAdapter bulletinAdapter;

    @Override
    protected int setLayout() {
        return R.layout.fragment_recommend_bulletin;
    }

    @Override
    protected void initView() {
        recyclerView = bindVie(R.id.recyclerView_bulletin_recommend);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    }
    @Override
    protected void intiData() {

        bulletinAdapter = new BulletinAdapter(getContext());
//        StringRequest stringRequest = new StringRequest(URLValues.LETTERS_URL, new Response.Listener<String>() {
//            @Override
//            public void onResponse(String response) {
////                Toast.makeText(mcontext, "请求成功", Toast.LENGTH_SHORT).show();
//                //请求成功
//                Gson gson = new Gson();
//                bulletinBean = gson.fromJson(response,BulletinBean.class);
//                bulletinAdapter.setaLists(bulletinBean);
//
//                recyclerView.setAdapter(bulletinAdapter);
//            }
//        }, new Response.ErrorListener() {
//            @Override
//            public void onErrorResponse(VolleyError error) {
//                Log.d("BulletinFragment", "请求失败");
//            }
//        });
//        SingleQueue.getInstance().addRequest(stringRequest);

        mNetTool.getNetData(URLValues.LETTERS_URL, BulletinBean.class, new NetTool.NetListener<BulletinBean>() {
            @Override
            public void onSuccess(BulletinBean bulletinBean) {
                bulletinAdapter.setaLists(bulletinBean);
                recyclerView.setAdapter(bulletinAdapter);
            }

            @Override
            public void onError(String errorMsg) {

            }
        });

    }

}
